package com.youlu.campus.service.data.impl;

import com.youlu.campus.entity.data.DataSimplingTaskDetail;
import com.youlu.campus.service.data.DataSimplingTaskDetailService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.Objects;

@Slf4j
@Service
public class DataSimplingTaskDetailServiceImpl implements DataSimplingTaskDetailService {
    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public boolean create(DataSimplingTaskDetail req) {
        req.setId(null);
        if (Objects.isNull(req.getCreatedTime())) {
            req.setCreatedTime(new Date());
        }
        req = mongoTemplate.insert(req);
        if (StringUtils.isNotBlank(req.getId())) {
            return true;
        }
        return false;
    }
}
